package cn.edu.nchu.fragmentdemo.utils;

/**
 * @className: DateConverter
 * @description: 时间格式转换工具
 * @author: Kuangkeli
 * @date: 2023/09/25 14:43
 **/

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateConverter {

    public static Date toDate(Long timestamp) {
        return timestamp == null ? null : new Date(timestamp);
    }


    public static Long toTimestamp(Date date) {
        return date == null ? null : date.getTime();
    }


    public static String toDateString(Long timestamp) {
        if (timestamp == null) {
            return null;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        return dateFormat.format(new Date(timestamp));
    }
}
